package com.coreJava.设计模式.原型模式;

import java.io.*;
import java.util.Map;

/**
 * 作者: LCG
 * 日期: 2019/9/5 11:01
 * 描述:
 */
public class Order implements Serializable,Cloneable {

    private String goodsName;
    private String brandName;
    private Map map;

    private int qunatity;

    private User user;

    public int getQunatity() {
        return qunatity;
    }

    public void setQunatity(int qunatity) {
        this.qunatity = qunatity;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public String getBrandName() {
        return brandName;
    }

    public void setBrandName(String brandName) {
        this.brandName = brandName;
    }

    public Map getMap() {
        return map;
    }

    public void setMap(Map map) {
        this.map = map;
    }

    /**
     * 浅克隆
     * @return
     * @throws CloneNotSupportedException
     */
    public Order clone() throws CloneNotSupportedException {

       return   (Order)super.clone();
    }

    /**
     * 深克隆
     * @return
     * @throws IOException
     * @throws ClassNotFoundException
     */
    public  Order deepClone() throws IOException, ClassNotFoundException {

        ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);

        ByteArrayInputStream byteArrayInputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream=new ObjectInputStream(byteArrayInputStream);

        return (Order) objectInputStream.readObject();


    }


}
